#ifndef _Charnode_h
#define _Charnode_h

#define DEBUG 1
#if DEBUG 
#define LOG(s) cout<<s<<endl;
#else
#define LOG(s) //
#endif

using namespace std;

template <class TYPE>
class Charnode
{
	TYPE ch;
	int count;
	Charnode *left;
	Charnode *right;

public :
	Charnode(TYPE ch, int count = 0);
	Charnode(const Charnode * New);
	int GetCount();
	int Value();
	void SetLeft(Charnode * left);
	void SetRight(Charnode * right);
	Charnode * GetLeft(void);
	Charnode * GetRight(void);
	TYPE GetChar(void);
	void show();
	bool operator <(Charnode &obj2);

	void setChar(TYPE ch);
};



template <class TYPE>
Charnode<TYPE>::Charnode(TYPE ch,int count)
{
	LOG("new Charnode"<<count<<"requested");
	this->ch = ch;
	this->count = count;
	this->left = this->right = NULL;
}

template <class TYPE>
Charnode<TYPE>::Charnode(const Charnode * New)
{
	LOG("new Charnode"<<New->count<<"requested");
			
	this->ch = New->ch;
	this->count = New->count;
	this->left = New->left;
	this->right = New->right;
}

template <class TYPE>
int Charnode<TYPE>::GetCount()
{
	return count;
}

template <class TYPE>
int Charnode<TYPE>::Value()
{
	return count;
}

template <class TYPE>
void Charnode<TYPE>::SetLeft(Charnode * left)
{
	this->left = left;
}

template <class TYPE>
void Charnode<TYPE>::SetRight(Charnode * right)
{
	this->right = right;
}

template <class TYPE>
Charnode<TYPE> * Charnode<TYPE>::GetLeft(void)
{
	return left;
}

template <class TYPE>
Charnode<TYPE> * Charnode<TYPE>::GetRight(void)
{
	return right;
}

template <class TYPE>
TYPE Charnode<TYPE>::GetChar(void)
{
	return ch;
}

template <class TYPE>
void Charnode<TYPE>::show()
{
	cout<<ch<<'\t'<<count<<endl;
}

template <class TYPE>
bool Charnode<TYPE>::operator <(Charnode &obj2)
{
	return (count < obj2.GetCount());
}

template <class TYPE>
void Charnode<TYPE>::setChar(TYPE ch)
{
	this->ch = ch;
}

#endif
